﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.DAL;
using FilStartUps.Helper;

namespace FilStartUps.Account
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                LinkButton lkHome = (LinkButton)FilStartUps_PageNav1.FindControl("lbLgout");
                LinkButton lkProfile = (LinkButton)FilStartUps_PageNav1.FindControl("lbProfile");
                lkProfile.Visible = true;
                lkHome.Visible = true;
            }

        }

        protected void btapply_Click(object sender, EventArgs e)
        {
            using (FilStartUpsEntities db_connect = new FilStartUpsEntities())
            {
                var user_ = db_connect.Members.Where(m => m.emailaddress.Equals(User.Identity.Name)).SingleOrDefault();
                string currentpw = txtcurrentpw.Text.Trim();

                if (user_.password == Helper.Helper.HashPassword(currentpw))
                {
                    user_.password = Helper.Helper.HashPassword(txtnewpw.Text.Trim());
                    user_.confirmpassword = Helper.Helper.HashPassword(txtconfirmpw.Text.Trim().ToUpper());
                    db_connect.SaveChanges();
                    Response.Redirect("~/Account/MemberProfile.aspx");
                }
                else
                {
                    //Error Msg
                }

            }
        }

        protected void btncancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Account/MemberProfile.aspx");
        }
    }
}